var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all) __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if ((from && typeof from === 'object') || typeof from === 'function') {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, {
          get: () => from[key],
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
        });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (
  (target = mod != null ? __create(__getProtoOf(mod)) : {}),
  __copyProps(
    // If the importer is in node compatibility mode or this is not an ESM
    // file that has been converted to a CommonJS file using a Babel-
    // compatible transform (i.e. "__esModule" has not been set), then set
    // "default" to the CommonJS "module.exports" for node compatibility.
    isNodeMode || !mod || !mod.__esModule
      ? __defProp(target, 'default', { value: mod, enumerable: true })
      : target,
    mod,
  )
);
var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', { value: true }), mod);

// src/CheckableTags/index.tsx
var CheckableTags_exports = {};
__export(CheckableTags_exports, {
  default: () => CheckableTags_default,
});
module.exports = __toCommonJS(CheckableTags_exports);
var import_antd = require('antd');
var import_react = __toESM(require('react'));
var import_icons = require('@ant-design/icons');
var import_classnames = __toESM(require('classnames'));
var import_style = require('antd/es/tag/style/index.js');
var import_createField = __toESM(require('../createField'));
var import_index = require('./index.less');
var CheckableTag = (0, import_react.forwardRef)(
  (
    {
      value,
      onChange,
      options,
      style,
      multiple = true,
      folded,
      tagProps,
      checkedTagProps,
      className,
    },
    ref,
  ) => {
    const [foldState, setFoldState] = (0, import_react.useState)(true);
    const checkedVals = (0, import_react.useMemo)(() => {
      if (multiple) return value ?? [];
      return value ? [value] : [];
    }, [value, multiple]);
    const handleAdd = (0, import_react.useCallback)(
      (key) => {
        const newValue = multiple ? [...(checkedVals ?? []), key] : key;
        onChange == null ? void 0 : onChange(newValue);
      },
      [checkedVals, multiple],
    );
    const handleRemove = (0, import_react.useCallback)(
      (key) => {
        if (multiple) {
          onChange == null ? void 0 : onChange((checkedVals ?? []).filter((it) => it !== key));
        } else {
          onChange == null ? void 0 : onChange(void 0);
        }
      },
      [checkedVals, multiple],
    );
    const getTagChild = (option) => {
      return (checkedVals == null ? void 0 : checkedVals.includes(option.value))
        ? /* @__PURE__ */ import_react.default.createElement(
            import_antd.Tag,
            {
              key: option.value,
              color: 'blue',
              ...tagProps,
              ...checkedTagProps,
              className: 'szzj-checkable-tag',
              onClick: () => handleRemove(option.value),
            },
            option.label,
          )
        : /* @__PURE__ */ import_react.default.createElement(
            import_antd.Tag,
            {
              key: option.value,
              ...tagProps,
              className: 'szzj-checkable-tag',
              onClick: () => handleAdd(option.value),
            },
            option.label,
          );
    };
    return /* @__PURE__ */ import_react.default.createElement(
      'div',
      {
        className: (0, import_classnames.default)('szzj-checkable-tags', className),
        style,
        ref,
      },
      /* @__PURE__ */ import_react.default.createElement(
        'div',
        { className: 'szzj-checkable-tag-wrap' },
        options.map((optionItem, index) => {
          if (foldState && folded && index >= folded) return null;
          return getTagChild(optionItem);
        }),
      ),
      folded &&
        folded > 0 &&
        (options == null ? void 0 : options.length) > folded &&
        /* @__PURE__ */ import_react.default.createElement(
          'a',
          {
            className: 'szzj-checkable-tags-expand',
            onClick: () => setFoldState(!foldState),
          },
          foldState ? '展开' : '收起',
          foldState
            ? /* @__PURE__ */ import_react.default.createElement(
                import_icons.CaretDownOutlined,
                null,
              )
            : /* @__PURE__ */ import_react.default.createElement(
                import_icons.CaretUpOutlined,
                null,
              ),
        ),
    );
  },
);
var CheckableTags_default = (0, import_createField.default)(CheckableTag);
